import React, { PropTypes } from 'react';
import TweenOne from 'rc-tween-one';

import { Menu, Icon, Switch, Breadcrumb, notification, Popover, Button, Modal, Form, Input, message} from 'antd';
const SubMenu = Menu.SubMenu;

import { Router, Route, IndexRoute, Link } from 'react-router';

import './less/leftMenu.less';

class LeftMenu extends React.Component {
  static contextTypes = {

  };

  static defaultProps = {

  };

  constructor(props){
    super(props);
    this.state = {
        dataSource:new Array(),
        clicked:'0'
    }
  }

  componentDidMount(){
    switch(this.props.location.query.id){
    case '1':
        this.setState({
          clicked:'11',
          dataSource:[{
            id:1,
            text:'用户管理',
            pathname:'/app/user',
            children:[{
              id:11,
              text:'员工中心',
              pathname:'/app/user/center',
              children:[]
            },{
              id:12,
              text:'员工入职',
              pathname:'/app/user/into',
              children:[]
            },{
              id:13,
              text:'人员管理',
              pathname:'/app/app',
              children:[]
            },{
              id:14,
              text:'部门管理',
              pathname:'/app/app',
              children:[]
            },{
              id:15,
              text:'岗位管理',
              pathname:'/app/app',
              children:[]
            },{
              id:16,
              text:'角色管理',
              pathname:'/app/app',
              children:[]
            },{
              id:17,
              text:'群组管理',
              pathname:'/app/app',
              children:[]
            }]
          }]
        })
        break;
    case '4':
        this.setState({
          clicked:'11',
          dataSource:[{
            id:1,
            text:'物业管理',
            pathname:'/app/estate',
            children:[{
              id:11,
              text:'收费项目',
              pathname:'/app/estate/project',
              children:[]
            },{
              id:12,
              text:'缴费列表',
              pathname:'/app/estate/payment',
              children:[]
            },{
              id:13,
              text:'付款方式',
              pathname:'/app/estate/method',
              children:[]
            },{
              id:15,
              text:'收费标准',
              pathname:'/app/estate/standard',
              children:[]
            },{
              id:16,
              text:'费用时间',
              pathname:'/app/estate/time',
              children:[]
            },{
              id:17,
              text:'催费记录',
              pathname:'/app/estate/record',
              children:[]
            },{
              id:18,
              text:'图表统计',
              pathname:'/app/estate/stat',
              children:[]
            }]
          }]
        })
        break;
      case '7':
          this.setState({
            clicked:'111',
            dataSource:[{
              id:1,
              text:'房源管理',
              pathname:'/app/room',
              children:[{
                id:11,
                text:'所属城市',
                pathname:'/app/room/city',
                children:[{
                  id:111,
                  text:'城市列表',
                  pathname:'/app/room/city/list',
                  children:[]
                },{
                  id:112,
                  text:'区域列表',
                  pathname:'/app/room/city/area',
                  children:[]
                }]
              },{
                id:12,
                text:'所属项目',
                pathname:'/app/room/project',
                children:[{
                  id:121,
                  text:'楼盘列表',
                  pathname:'/app/room/project/list',
                  children:[]
                }]
              },{
                id:13,
                text:'所属房源',
                pathname:'/app/room/house',
                children:[{
                  id:131,
                  text:'户型列表',
                  pathname:'/app/room/house/style',
                  children:[]
                },{
                  id:132,
                  text:'栋号列表',
                  pathname:'/app/room/house/build',
                  children:[]
                },{
                  id:133,
                  text:'单元列表',
                  pathname:'/app/room/house/unit',
                  children:[]
                },{
                  id:134,
                  text:'楼层列表',
                  pathname:'/app/room/house/floor',
                  children:[]
                },{
                  id:135,
                  text:'房源列表',
                  pathname:'/app/room/house/source',
                  children:[]
                },{
                  id:136,
                  text:'车位列表',
                  pathname:'/app/room/house/car',
                  children:[]
                }]
              },{
                id:14,
                text:'收费类别',
                pathname:'/app/room/cost',
                children:[{
                  id:141,
                  text:'付款方式',
                  pathname:'/app/room/cost/pay',
                  children:[]
                },{
                  id:142,
                  text:'付款周期',
                  pathname:'/app/room/cost/cycle',
                  children:[]
                },{
                  id:143,
                  text:'费用类别',
                  pathname:'/app/room/cost/classify',
                  children:[]
                }]
              },{
                id:15,
                text:'销售租赁',
                pathname:'/app/room/voucher',
                children:[{
                  id:151,
                  text:'销售记录',
                  pathname:'/app/room/voucher/sale',
                  children:[]
                },{
                  id:152,
                  text:'租赁记录',
                  pathname:'/app/room/voucher/rent',
                  children:[]
                },{
                  id:153,
                  text:'房源客户',
                  pathname:'/app/room/voucher/client',
                  children:[]
                }]
              }]
            }]
          })
          break;
        case '8':
            this.setState({
              clicked:'111',
              dataSource:[{
                id:1,
                text:'收银结算',
                pathname:'/app/cashier',
                children:[{
                  id:11,
                  text:'收银管理',
                  pathname:'/app/cashier/cashier',
                  children:[{
                    id:111,
                    text:'结算界面',
                    pathname:'/app/cashier/cashier/page',
                    children:[]
                  },{
                    id:112,
                    text:'退款列表',
                    pathname:'/app/cashier/cashier/list',
                    children:[]
                  },{
                    id:113,
                    text:'退款明细',
                    pathname:'/app/cashier/cashier/refund',
                    children:[]
                  }]
                },{
                  id:12,
                  text:'结算管理',
                  pathname:'/app/cashier/clearing',
                  children:[{
                    id:121,
                    text:'申请结算',
                    pathname:'/app/cashier/clearing/apply',
                    children:[]
                  },{
                    id:122,
                    text:'结算列表',
                    pathname:'/app/cashier/clearing/list',
                    children:[]
                  }]
                },{
                  id:13,
                  text:'评价管理',
                  pathname:'/app/cashier/evaluate',
                  children:[{
                    id:131,
                    text:'订单评价',
                    pathname:'/app/cashier/evaluate/order',
                    children:[]
                  },{
                    id:132,
                    text:'意见反馈',
                    pathname:'/app/cashier/evaluate/advice',
                    children:[]
                  }]
                }]
              }]
            })
            break;
      default:
        this.setState({
          clicked:'11',
          dataSource:[{
            id:1,
            text:'会员管理',
            pathname:'/app/member',
            children:[{
              id:11,
              text:'会员列表',
              pathname:'/app/member/list',
              children:[]
            },{
              id:12,
              text:'会员卡表',
              pathname:'/app/member/table',
              children:[]
            },{
              id:13,
              text:'积分记录',
              pathname:'/app/member/record',
              children:[]
            },{
              id:14,
              text:'升级记录',
              pathname:'/app/member/up',
              children:[]
            },{
              id:15,
              text:'会员类别',
              pathname:'/app/member/classify',
              children:[]
            },{
              id:16,
              text:'商家类别',
              pathname:'/app/member/shops',
              children:[]
            },{
              id:17,
              text:'会员卡类',
              pathname:'/app/member/card',
              children:[]
            },{
              id:18,
              text:'费用类别',
              pathname:'/app/member/fee',
              children:[]
            },{
              id:19,
              text:'积分折算',
              pathname:'/app/member/score',
              children:[]
            }]
          }]
        })
    }


  }

  _renderMenus(data){
    return data.map((ele,index) => {
      if(ele.children.length === 0){
        return (
          <Menu.Item key={ele.id}><Link to={{pathname:ele.pathname,query:{id:this.props.location.query.id}}}>{ele.text}</Link></Menu.Item>
        )
      }else{
        return (
            <SubMenu key={ele.id} title={<span><Icon type="user" /><span>{ele.text}</span></span>}>
                {this._renderMenus(ele.children)}
            </SubMenu>
        )
      }
    })
  }

  handleClick(e){
    this.setState({
      clicked: e.key
    });
  }

  render() {
    return (
      <Menu
        onClick={this.handleClick.bind(this)}
        defaultOpenKeys={['1','11']}
        selectedKeys={[this.state.clicked]}
        mode="inline"
        theme="dark"
      >
         {this._renderMenus(this.state.dataSource)}
      </Menu>
    )
  }
}

export default LeftMenu;
